package com.xit.cloud.controller;

import com.xit.cloud.entity.user;
import com.xit.cloud.service.adminService;
import com.xit.cloud.service.vmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author malguy-wang sir
 * @create ---
 */
@Controller
@RequestMapping("/admin")
public class adminController {
    @Autowired
    public com.xit.cloud.service.adminService adminService;
//    @PreAuthorize("hasAnyAuthority('admin')")
    //加了这个注解,如果没有权限,不会跳到403页面,而是报404
    @Secured({"ROLE_admin"}) //ROLE_admin和ROLE_manager可以访问
    @RequestMapping("/all")
    @ResponseBody
    public List<user> all(){
        List<user> all = adminService.selectAllUser();
        return all;
    }

    @Autowired
    public com.xit.cloud.service.vmService vmService;
    @Secured({"ROLE_admin"}) //ROLE_admin和ROLE_manager可以访问
    @ResponseBody
    @RequestMapping("/allVM")
    public List allVM(){
        try {
            return vmService.show();
        } catch (Exception e) {
            return null;
        }
    }
}
